<?php

namespace App\Entity;

use App\Enum\LogTypeEnum;
use App\Repository\FeedbackRepository;
use App\Utils\Helper\LogHelper;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity(repositoryClass=FeedbackRepository::class)
 * @ORM\HasLifecycleCallbacks()
 */
class Feedback {
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @ORM\Column(type="string", length=255)
     */
    private $nickname;

    /**
     * @ORM\Column(type="string", length=255)
     */
    private $email;

    /**
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    private $content;

    /**
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    private $ip;

    /**
     * @ORM\Column(type="datetime", nullable=true)
     */
    private $created_at;

    /**
     * @ORM\Column(type="datetime", nullable=true)
     */
    private $updated_at;

    /**
     * @ORM\Column(type="boolean", length=255, nullable=true, options={"default"="0", "comment"="状态：0未读，1已读"})
     */
    private $status = 0;

    public function getId (): ?int {
        return $this->id;
    }

    public function getNickname (): ?string {
        return $this->nickname;
    }

    public function setNickname (string $nickname): self {
        $this->nickname = $nickname;

        return $this;
    }

    public function getEmail (): ?string {
        return $this->email;
    }

    public function setEmail (string $email): self {
        $this->email = $email;

        return $this;
    }

    public function getContent (): ?string {
        return $this->content;
    }

    public function setContent (?string $content): self {
        $this->content = $content;

        return $this;
    }

    public function getIp (): ?string {
        return $this->ip;
    }

    public function setIp (?string $ip): self {
        $this->ip = $ip;

        return $this;
    }

    public function getCreatedAt (): ?\DateTimeInterface {
        return $this->created_at;
    }

    public function setCreatedAt (?\DateTimeInterface $created_at): self {
        $this->created_at = $created_at;

        return $this;
    }

    public function getUpdatedAt (): ?\DateTimeInterface {
        return $this->updated_at;
    }

    public function setUpdatedAt (?\DateTimeInterface $updated_at): self {
        $this->updated_at = $updated_at;

        return $this;
    }

    public function getStatus (): ?bool {
        return $this->status;
    }

    public function setStatus (?bool $status): self {
        $this->status = $status;

        return $this;
    }

    /**
     * 删除之前 日志
     * @ORM\PreRemove()
     */
    public function buildLogByDelete () {
        $description = '昵称:['.$this->getNickname().'] 留言:['.$this->getContent().']';
        LogHelper::buildLog(LogTypeEnum::TYPE_FEEDBACK_DELETE, $description, $this);
    }
}
